package com.heima.test06;

public class Test {
    public static void main(String[] args) {
        //定义存储数组
        Girl[] arr = new Girl[4];

        //创建女朋友对象
        Girl g1 = new Girl("小白", 18, "萌萌哒", "吃东西");
        Girl g2 = new Girl("小灰", 20, "萌萌哒", "吃东西");
        Girl g3 = new Girl("小黄", 22, "萌萌哒", "吃东西");
        Girl g4 = new Girl("小绿", 21, "萌萌哒", "吃东西");

        //将对象存入数组
        arr[0] = g1;
        arr[1] = g2;
        arr[2] = g3;
        arr[3] = g4;

        //求和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            //定义对象取值
            sum += arr[i].getAge();
        }

        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getName() + " ," + arr[i].getAge() + " ," + arr[i].getGender() + " ," + arr[i].getHobby());
        }
        //平均值
        int avg = sum / arr.length;
        //统计年龄低于均值的个数，并打印信息
        int count = 0;

        System.out.println("-----低于平均年龄的----");
        //遍历低于avg
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getAge() < avg) {
                System.out.println(arr[i].getName() + " ," + arr[i].getAge() + " ," + arr[i].getGender() + " ," + arr[i].getHobby());
                count++;
            }
        }
        System.out.println(count + "个");
    }
}
